package com.ba.util;

import java.io.PrintWriter;
import java.io.StringWriter;

/**
 * @author Administrator
 * @package com.ba.util
 * @date 2020-10-29 21:20
 */
public class ErrorUtil {

    /**
     * 出错的信息转成字符串，打印到日志中
     * @param e
     * @return
     */
    public static String errorInfoToString(Throwable e) {
        // try-with-resource
        try(StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw)) {
            e.printStackTrace(pw);
            pw.flush();
            sw.flush();
            return sw.toString();
        } catch (Exception ignored) {
            throw new RuntimeException(ignored.getMessage(), ignored);
        }
    }
}
